import type { Action } from '@/types/login'
import {
  setTokenInfo,
  getTokenInfo,
  removeTokenInfo,
} from '@/utils/storage_token'
export default function reducer(
  state = getTokenInfo() || {
    token: '',
    refresh_token: '',
  },
  action: Action
) {
  const { type, payload } = action
  if (type === 'LOGIN') {
    // 登录
    // 持久化存储
    setTokenInfo(payload)
    return payload
  } else if (type === 'LOGOUT') {
    removeTokenInfo()
    return payload
  }
  return state
}
